import BaseScene from './BaseScene.js';
import GameUtils from '../utils/GameUtils.js';

export default class MenuScene extends BaseScene {
    constructor(game) {
        super(game);
        this.buttons = [];
        this.init();
    }

    init() {
        // 创建朋友模式按钮
        const friendButton = {
            x: this.game.canvas.width / 2,
            y: this.game.canvas.height / 2 - 100,
            width: 300,
            height: 100,
            text: '朋友模式',
            mode: 'friend',
            color: '#4CAF50',
            hoverColor: '#45a049'
        };

        // 创建情侣模式按钮
        const coupleButton = {
            x: this.game.canvas.width / 2,
            y: this.game.canvas.height / 2 + 100,
            width: 300,
            height: 100,
            text: '情侣模式',
            mode: 'couple',
            color: '#E91E63',
            hoverColor: '#d81b60'
        };

        this.buttons.push(friendButton, coupleButton);
    }

    update() {
        // 更新按钮状态
        this.buttons.forEach(button => {
            button.isHover = GameUtils.isPointInRect(
                this.game.mouseX,
                this.game.mouseY,
                button.x - button.width / 2,
                button.y - button.height / 2,
                button.width,
                button.height
            );
        });
    }

    render() {
        const ctx = this.game.ctx;
        
        // 绘制背景
        const currentMode = this.game.getGameMode();
        const background = this.game.getCurrentBackground();
        if (background) {
            ctx.drawImage(background, 0, 0, this.game.canvas.width, this.game.canvas.height);
        } else {
            // 默认背景色
            ctx.fillStyle = '#f5f5f5';
            ctx.fillRect(0, 0, this.game.canvas.width, this.game.canvas.height);
        }

        // 绘制半透明遮罩
        ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
        ctx.fillRect(0, 0, this.game.canvas.width, this.game.canvas.height);

        // 绘制标题
        ctx.fillStyle = '#fff';
        ctx.font = 'bold 48px Arial';
        ctx.textAlign = 'center';
        ctx.fillText('真心话大冒险', this.game.canvas.width / 2, 150);

        // 绘制副标题
        ctx.font = '24px Arial';
        ctx.fillText('选择游戏模式', this.game.canvas.width / 2, 200);

        // 绘制按钮
        this.buttons.forEach(button => {
            ctx.fillStyle = button.isHover ? button.hoverColor : button.color;
            GameUtils.drawRoundedRect(
                ctx,
                button.x - button.width / 2,
                button.y - button.height / 2,
                button.width,
                button.height,
                10
            );

            ctx.fillStyle = '#fff';
            ctx.font = 'bold 32px Arial';
            ctx.textAlign = 'center';
            ctx.textBaseline = 'middle';
            ctx.fillText(button.text, button.x, button.y);
        });
    }

    handleClick(x, y) {
        this.buttons.forEach(button => {
            if (GameUtils.isPointInRect(
                x,
                y,
                button.x - button.width / 2,
                button.y - button.height / 2,
                button.width,
                button.height
            )) {
                // 设置游戏模式并切换到大厅场景
                this.game.setGameMode(button.mode);
                this.game.sceneManager.switchTo('lobby');
            }
        });
    }
} 